/**
* 版权声明：厦门睿商网络科技有限公司 版权所有 违者必究
* 日    期：2020-02-17
*/
package com.rzico.basics.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.rzico.annotation.Log;
import com.rzico.base.BaseController;
import com.rzico.base.CommResult;
import com.rzico.basics.entity.Enterprise;
import com.rzico.basics.entity.MemberCategory;
import com.rzico.basics.service.EnterpriseService;
import com.rzico.entity.Filter;
import com.rzico.entity.Pageable;
import com.rzico.entity.PageResult;
import com.rzico.basics.entity.ProductCategory;
import com.rzico.basics.service.ProductCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.Api;
import com.rzico.util.StringUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.HashMap;
import java.util.Map;

/**
 * 产品分类控制层
 *
 * @author Rzico Boot
 * @version 1.0
 * @date 2020-02-17
 */
@Api(description = "产品分类接口")
@RestController
@RequestMapping("/productCategory")
public class ProductCategoryController extends BaseController {

    @Autowired
    private ProductCategoryService productCategoryService;

    @Autowired
    private EnterpriseService enterpriseService;

    /**
     * 查询产品分类
     *
     * @return
    */
    @ApiOperation("查询产品分类")
    @GetMapping("/list")
    @ApiImplicitParams({@ApiImplicitParam(name = "mchId", value = "商户号", dataType = "String", paramType = "query")
    }) public CommResult<ProductCategory> list(String mchId) {
        Map<String, Object> params = new HashMap<String, Object>();

        Enterprise enterprise = enterpriseService.findByMch(mchId);
        if (enterprise!=null) {
            params.put("enterpriseId", enterprise.getId());
        } else {
            return CommResult.error("没有开通企业");
        }

        params.put("isShow", true);
        params.put("sortField", "tree_path");
        params.put("sortType", "asc");
        List<ProductCategory> list = productCategoryService.selectTree(params);
        return CommResult.success(list);
    }


}
